package com.yingxin.yxerp.module.common.util;

import com.alibaba.fastjson.JSON;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class SmBeanUtils {

    private SmBeanUtils() {
    }

    public static <T> List copyProperties(List list, Class<T> targetClass) {
        if (list == null || list.size() == 0) {
            return new ArrayList();
        }
        return JSON.parseArray(JSON.toJSONString(list), targetClass);
    }

    public static String toString(Object value) {
        String bigDec = null;
        if (value != null) {
            if (value instanceof Integer) {
                bigDec = String.valueOf(value);
            } else if (value instanceof Double) {
                String aa = value.toString();
                bigDec = aa.substring(0, aa.lastIndexOf("."));
            } else if (value instanceof BigDecimal) {
                String aa = value.toString();
                bigDec = aa.substring(0, aa.lastIndexOf("."));
            } else if (value instanceof String) {
                String aa = value.toString();
                bigDec = aa;
            } else {
                throw new ClassCastException("Can Not make [" + value + "] into a BigDecimal.");
            }
        }
        return bigDec;
    }

}
